﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YXChatFormClient.Utility;

namespace YXChatFormClient.Component.Message
{
    public partial class MessageBoxFrom : Form
    {
        public MessageBoxFrom()
        {
            InitializeComponent();
        }
        private void picClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        private void picClose_MouseMove(object sender, MouseEventArgs e)
        {
            picClose.BackColor = Color.FromArgb(250, 81, 81);
            picClose.ImageLocation = ImageHelper.GetStaticImage("close_active.png");
        }

        private void picClose_MouseLeave(object sender, EventArgs e)
        {
            picClose.BackColor = Color.White;
            picClose.ImageLocation = ImageHelper.GetStaticImage("active.png");
        }
        public void AddContentToPanel(Control control)
        {
            this.panelContent.Controls.Clear();
            this.Width = control.Width;
            this.Height = 25 + control.Height;
            this.Font = control.Font;
            control.Dock = DockStyle.Fill;
            this.panelContent.Controls.Add(control);
        }
        #region 自定义拖动窗体
        [DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
        private static extern void ReleaseCapture();

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        private static extern void SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
        #endregion
        private void panelHeader_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }
        public void ShowMessage(Control control)
        {
            AddContentToPanel(control);
            this.ShowDialog();
        }
        #region 边框阴影
        private const int CS_DropShadow = 0x00020000;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DropShadow;
                return cp;
            }
        }
        #endregion
    }
}
